<template>
	<view class="page">
		
		<view class="head">
			<image src="../../../../static/jiaotou1.png" @click="gotoPage('/pages/user/user-car/user-car')"></image>
			<text>添加二手车</text>
		</view>
		<view class="null"></view>
		<view class="mycar-msg">
			<view class="mycar-msg1">
				<text>车辆类型:</text>
				<picker @change="seleceYears" range-key="type_name" :range="selectType" :value="index">
					<input type="text" placeholder="请选择" v-model="addcar_type" disabled="" />
				</picker>

			</view>
			<view class="mycar-msg2">
				<text>车牌号:</text>
				<input type="text" placeholder="请输入车牌号" v-model="addcar_plate" />
			</view>
			<view class="mycar-msg2">
				<text>手机号:</text>
				<input type="text" placeholder="请输入手机号" v-model="addcar_mobile" />
			</view>
		</view>
		<view class="upload">
			<text class="upload_title">请上传车辆信息</text>
			<view class="upload1">
				<view class="upload-imgs" @click="chooseImages('car_info1')">
					<image class="upload-imgs1" src="../../../../static/app/upload-bg-3.png" v-if="imageList.car_info1=='' "></image>
					<image class="upload-imgs2" src="../../../../static/app/upload-icon.png" v-if="imageList.car_info1=='' "></image>
					<image class="upload-imgs1" :src="imageList.car_info1" mode="" v-else></image>
				</view>
				<view class="upload-imgs upload-item2" @click="chooseImages('car_info2')">
					<image class="upload-imgs1" src="../../../../static/app/upload-bg-4.png" v-if="imageList.car_info2=='' "></image>
					<image class="upload-imgs2" src="../../../../static/app/upload-icon.png" v-if="imageList.car_info2=='' "></image>
					<image class="upload-imgs1" :src="imageList.car_info2" mode="" v-else></image>
				</view>
			</view>
			<text class="upload_title title2">请上传车辆照片</text>
			<view class=" upload2">
				
				<view class="upload-imgs upload-item2" @click="chooseImages('car_info4')">
					<image class="upload-imgs1" src="../../../../static/app/upload-bg-5.png" v-if="imageList.car_info4=='' "></image>
					<image class="upload-imgs2" src="../../../../static/app/upload-icon.png" v-if="imageList.car_info4=='' "></image>
					<image class="upload-imgs1" :src="imageList.car_info4" mode="" v-else></image>
				</view>
			</view>
			<!-- <view class=" upload2">
				<block class="car_image" v-for="(image,index) in car_info3" :key="index">
					<view class="upload-item">
						<image class="upload-imgs1" :src="image" mode=""></image>
						<view class="icon iconfont icon-guanbi" @tap="delect(index)"></view>
					</view>
				</block>
				<view class="upload-imgs upload-item2" @click="chooseImages('car_info3')">
					<image class="upload-imgs1" src="../../../../static/app/upload-bg-4.png"></image>
					<image class="upload-imgs2" src="../../../../static/app/upload-icon.png"></image>
				</view>
			</view> -->
			<!-- <text class="title title2">分配司机</text>
			<view class="select">
				<picker class="select-driver" @change="seleceDriver" range-key="realname" :range="selectDriver" :value="driverId">
					<input type="text" value="driver" v-model="driver" disabled="" />
				</picker>				
				<image src="../../../../static/app/jiaotou2.png"></image>
			</view> -->

		</view>
		<view class="carMsg">
			<view class="msg-item">
				<view class="buyAddress">
					<text>卖车地点:</text>
					<view class="buySelect" @click="location_select">
						<input type="text" v-model="carMsg.address" disabled="" placeholder="请选择" />
						<image src="../../../../static/jiantou3.png"></image>
					</view>
				</view>
			</view>
			<view class="msg-item">
				<view class="buyAddress">
					<text>车辆介绍:</text>
					<view class="buySelect carType">
						<input type="text" v-model="carMsg.introduce" placeholder="请输入" />
					</view>
				</view>
			</view>
			<view class="msg-item">
				<view class="buyAddress">
					<text>车辆品牌:</text>
					<view class="buySelect carType">
						<input type="text" v-model="carMsg.type" placeholder="请输入车量品牌" />
					</view>
				</view>
			</view>
			<view class="msg-item">
				<view class="buyAddress">
					<text>表显里程:</text>
					<view class="buySelect carJourney">
						<input type="number" v-model="carMsg.journey" placeholder="请输入" />
						<text>公里</text>
					</view>
				</view>
			</view>
			<view class="msg-item">
				<view class="buyAddress">
					<text>上牌时间:</text>
					<view class="buySelect carType">						
						<picker mode="date" fields="month" @change="bindDateChange">
							<input type="text" disabled="" v-model="carMsg.time" placeholder="请选择上牌时间" />
						</picker>
					</view>
				</view>
			</view>
			<view class="msg-item">
				<view class="buyAddress">
					<text>出售价格:</text>
					<view class="buySelect carJourney">
						<input type="number" v-model="carMsg.discharge" placeholder="请输入" />
						<text>元</text>
					</view>
				</view>
			</view>
			<view class="msg-item">
				<view class="buyAddress">
					<text>变速箱:</text>
					<view class="buySelect" @click="boxSelect">
						<input type="text" v-model="carMsg.box" disabled="" placeholder="请选择" />
						<image src="../../../../static/jiantou3.png"></image>
					</view>
				</view>
			</view>
			<view class="msg-item">
				<view class="buyAddress">
					<text>车辆过户:</text>
					<view class="buySelect carJourney">
						<input type="number" v-model="carMsg.transfer" placeholder="请输入" />
						<text>次</text>
					</view>
				</view>
			</view>
			<!-- <view class="msg-item">
				<view class="buyAddress">
					<text>车牌号</text>
					<view class="buySelect carCode">
						<input type="text" v-model="carMsg.serial" placeholder="请输入车牌号" />

					</view>
				</view>
			</view> -->
			<view class="msg-item">
				<view class="buyAddress">
					<text>新车含税价:</text>
					<view class="buySelect carJourney">
						<input type="number" v-model="carMsg.price" placeholder="请输入" />
						<text>元</text>
					</view>
					
				</view>
			</view>
		</view>

		<button class="submit" @click="$noMultipleClicks(formSubmit)">提交</button>
		<view class="box" v-if="box">
			<view class="shadow" @click="close"></view>
			<view class="box-content">
				<view class="box-head">
					<text>变速箱</text>
					<image @click="close" src="../../../../static/close.png"></image>
				</view>
				<view class="box-type">
					<span ref="manumotive"  @click="getType1()">{{type1}}</span>
					<span ref="voluntarily" @click="getType2()">{{type2}}</span>
				</view>
			</view>
		</view>
		<view class="location-item" v-if="location_show">
			<view class="header w100 flexw" :style="{height:customBar}">
				<view class="placeholder" :style="{height:statusBar}"></view>
				<view class="flex w100">
					<input class="input" :focus="true" @confirm="doneInput" type="text" confirm-type="search" :adjust-position="false"
					 @input="onInput" placeholder="搜索城市 中文/首字母" v-model="searchValue" />
					<!-- <view class="back_div fsmall bold blue" @tap="back()">
						搜索
					</view> -->
					<view class="close" @click="closeLocation"> 取消 </view>
				</view>
			</view>
		
			<scroll-view class="w100" scroll-y="true" :scroll-into-view="scrollIntoId" :style="{height:scrollHeight}"
			 @touchmove.stop.prevent>
				<view class="location-wrap" v-if="disdingwei" id="hot">
					<!-- 定位模块 -->
					<view class="dingwei">
						<view class="grey flexa fsmall">
							当前定位
						</view>
						<view class="dingwei_city">
							<view class="dingwei_city_one" @tap="back_city(location,true)">
								{{location}}
							</view>
						<!-- 	<view class="location-style">{{location}}</view> -->
							<view class="bold blue fmiddle" @click="getLocation()">
								<text>{{po_tips}}</text>
							</view>
						</view>
						<!-- <view class="dingwei_city">
							<view class="dingwei_city_one" @tap="back_city(position,true)">
								{{position?position.city:'定位失败'}}
							</view>
							<view class="bold blue fmiddle" @click="getWarpweft"> 
								<text>{{po_tips}}</text>
							</view>
						</view> -->
					</view>
		
					<!-- 最近模块 -->
					<view class="dingwei" v-if="cacheLocation">
						<view class="grey flexa fsmall">
							最近访问
						</view>
						<view class="dingwei_city dingwei_city_zuijin">
							<view class="dingwei_city_one" v-for="(item,index) in cacheLocation" :key="index" @tap="back_city(item)">
								{{item.city_name}}
							</view>
						</view>
					</view>
					<!-- 热门 -->
					<view class="dingwei" v-if="hotCity">
						<view class="grey flexa fsmall">
							热门城市
						</view>
						<view class="dingwei_city dingwei_city_zuijin">
							<view class="dingwei_city_one" v-for="(item,index) in hotCity" :key="index" @tap="back_city(item)">
								{{item.city_name}}
							</view>
						</view>
					</view>
				</view>
				<!-- 城市列表 -->
				<view v-if="searchValue == ''" v-for="(item, index) in list" :id="item.idx" :key="item.idx">
					<view class="letter-header bold">{{ item.idx }}</view>
					<view class="city-div" v-for="(city, i) in item['cities']" :key="i" @tap="back_city(city)">
						<text class="city" >{{ city.city_name }}</text>
					</view>
				</view>
				<!-- 搜索结果 -->
				<view class="city-div" v-for="(item, index) in searchList" :key="index" @tap="back_city(item)">
					<text class="city">{{ item.city_name }}</text>
				</view>
				<view class="placeholder footer"></view>
			</scroll-view>
		
			<!-- 右侧字母 -->
			<view class="letters" id="list" v-if="searchValue == ''" @touchstart="touchStart" @touchmove.stop.prevent="touchMove"
			 @touchend="touchEnd">
				<view class="fmin" @click="scrollTo('hot')">最近</view>
				<view class="fmin" v-for="item in letter" :key="item.idx">{{ item.idx }}</view>
			</view>
			<!-- 选中之后字母 -->
			<view class="mask" v-if="touchmove">
				<view class="mask-r bold">{{scrollIntoId}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import Citys from './Citys/index.list.js'
	import calendar from '../../../../components/uni-calendar/uni-calendar.vue'
	export default {
		components: {
			calendar
		},
		data() {
			return {
				imageList: {
					car_info1: '',
					car_info2: '',
					// car_info3: '',
					car_info4:'',
				},
				addcar_type: '', //车辆类型
				type_id:'',//车辆类型id
				addcar_plate: '', //车牌号
				driver: '请选择', //分配司机
				addcar_mobile:'',//手机号
				car_info3: [],
				selectType: [],
				selectDriver: [],
				index: '0',
				driverId: '0',
				carMsg: {
					introduce: '', //车辆介绍
					//serial: '', //车牌号
					address: '', //卖车地点
					type: '', //车量品牌
					journey: '', //表显路程
					time: '', //上牌时间
					discharge: '', //排放量
					box: '', //变速箱
					transfer: '', //车辆过户次数
					price: '', //新车含税价
				},
				box: false, //变速箱
				
				location_show:false,
				statusBar: '0px',
				customBar: '45px',
				
				winHeight: 0,
				itemHeight: 0,
				winOffsetY: 0,
				touchmove: false,
				
				
				scrollHeight: this.statusBarHeight,
				ImgUrl: this.ImgUrl,
				letter: [],
				
				searchValue: '',
				scrollIntoId: '',
				list: [],
				tId: null,
				searchList: [],
				showMask: false,
				disdingwei: true,
				cacheLocation: '', //最近访问
				position: '', //位置
				
				po_tips: '重新定位',
				hotCity: '',
				location: '',
				type1:'自动',
				type2:'手动',
				noClick:true,
				nowdate:'',//当前时间
			};
		},
		// watch: {
		// 	list() {
		// 		setTimeout(() => {
		// 			this.setList()
		// 		}, 100)
		// 	}
		// },
		onLoad(option) {
			//this.localTime();
			this.getCar_type();
			this.getDriver();
			this.scrollHeight = uni.getSystemInfoSync().windowHeight - parseInt(this.customBar) + 'px'
			//获取存储的最近访问
			var that = this
			uni.getStorage({
				key: 'location_key',
				success: function(res) {
					that.cacheLocation = res.data
				}
			});
			this.letter = Citys.index;
			this.list = Citys.list;
			this.getLocation();
		},
		methods: {
			/* 选择日期 */
			bindDateChange(e){		
				this.carMsg.time = e.target.value;
				//console.log(this.date)
			},
			open() {
				this.$refs.calendar.open();
			},
			confirm(e) {
				//console.log(e.fulldate);
				this.carMsg.time = e.fulldate;
			},
			localTime() {
				setInterval(() => {
					this.nowDate()
				}, 3000)
			},
			/* 获取当前时间 */
			nowDate() {
				let today = new Date();
				let year = today.getFullYear()
				let month = today.getMonth() + 1;
				let day = today.getDate()
				month = checkTime(month)
				day = checkTime(day)
				function checkTime(i) {
					if (i < 10) {
						i = "0" + i;
					}
					return i;
				}			
				let temp = `${year}-${month}-${day} `
				this.nowdate = temp
				console.log(this.nowdate);
			},
			location_select(){
				this.location_show=true;
			},
			// getValue() {
			// 	console.log(111)
			// },
			/* 获取当前位置 */
			getLocation() {
				let self = this;
				uni.getLocation({
					type: 'wgs84',
					geocode: true,
					success: function(res) {
						self.location = res.address.city;
					},
					fail: function(res) {
						//console.log("fail");
					}
				});
			},
			back(e) {
				//你自己实现 返回上一页
				console.log(e);
				this.carMsg.address=e.city_name;
				this.location_show=false;
				//this.carMsg.address = e.location;
				// uni.navigateTo({
				// 	url: '/pages/user/user-car/add-usercar/add-usercar?city_name=' + e.city_name
				// })
				
			},
			setList() {
				uni.createSelectorQuery()
					.in(this)
					.select('#list')
					.boundingClientRect()
					.exec(ret => {
						console.log(ret);
						this.winOffsetY = ret[0].top
						this.winHeight = ret[0].height
						this.itemHeight = this.winHeight / this.list.length
					})
			
			},
			touchStart(e) {
				this.touchmove = true
				let pageY = e.touches[0].pageY
				let index = Math.floor((pageY - this.winOffsetY) / this.itemHeight)
				if (this.list[index]) {
					this.scrollIntoId = this.list[index].idx
				}
			},
			touchMove(e) {
				let pageY = e.touches[0].pageY
				let index = Math.floor((pageY - this.winOffsetY) / this.itemHeight)
				if (this.list[index] && this.list[index].idx === this.scrollIntoId) {
					return false
				}
				if (this.list[index]) {
					this.scrollIntoId = this.list[index].idx
				}
			},
			touchEnd() {
				this.touchmove = false
				this.touchmoveIndex = -1
			},
			
			doneInput() {
				uni.hideKeyboard()
			},
			move(e) {
				console.log(111, e);
			},
			getId(index) {
				return this.letter[index];
			},
			query(source, text) {
				let res = [];
				var self = this;
				let len = source.length
				var text = text.toLowerCase()
				for (let i = 0; i < len; i++) {
					//单字母搜索
					if (text.length == 1 && /^[a-zA-Z]$/.test(text)) {
						let arr = []
						let idx = text.toUpperCase()
						if (idx == source[i].idx) {
							console.log(222, source[i]);
							return source[i].cities
						}
					}
					//其它搜索
					if (source[i].cities) {
						let _len = source[i].cities.length
						for (var n = 0; n < _len; n++) {
							let _item = source[i].cities[n]
							if (new RegExp('^' + text).test(_item.city_name)) {
								res.push(_item);
								continue;
							}
							if (new RegExp('^' + text).test(_item.city_pinyin)) {
								res.push(_item);
								continue;
							}
							if (new RegExp('^' + text).test(_item.py)) {
								res.push(_item);
								continue;
							}
			
						}
					}
				}
			
				return res;
			},
			
			isString(obj) {
				return typeof obj === 'string';
			},
			
			onInput(e) {
				const value = e.target.value;
				if (value !== '' && this.list) {
					const queryData = this.query(this.list, String(value).trim());
					this.searchList = queryData;
					this.disdingwei = false
				} else {
					this.searchList = [];
					this.disdingwei = true
				}
			},
			
			back_city(item, hasLocation = false) {
				
				console.log(333, item);
				uni.setStorageSync('location_city', item.city_name);
				// this.$store.commit('getCity',item.city_name)
				uni.switchTab({
					url: '/pages/index/index'
				})
				if (item) {
					//是否是定位 
					if (hasLocation) {
						item = {
							//city_name: item.city,
							city_name: item
						}
					}
					uni.$emit('selectCity', item);
					//unshift 把数据插入到首位，与push相反
					if (!this.cacheLocation) this.cacheLocation = []
					this.cacheLocation.unshift(item)
					this.searchValue = "";
					this.disdingwei = true
					var arr = this.cacheLocation
					//数组去重
					function distinct(arr) {
						let newArr = []
						for (let i = 0; i < arr.length; i++) {
							if (newArr.indexOf(arr[i]) < 0) {
								newArr.push(arr[i])
							}
						}
						return newArr
					}
					this.cacheLocation = distinct(arr).slice(0, 5)
					uni.setStorage({
						key: 'location_key',
						data: this.cacheLocation
					});
				}
				this.back(item)
			},
			// getWarpweft() {
			// 	//自己写吧
			// 	var that = this
			// 	that.po_tips = '定位中...';
			// 	uni.chooseLocation({
			// 		success: function(res) {
			// 			console.log(res);
			// 			console.log('位置名称：' + res.name);
			// 			console.log('详细地址：' + res.address);
			// 			console.log('纬度：' + res.latitude);
			// 			console.log('经度：' + res.longitude);
			// 		}
			// 	});
			// },
			closeLocation(){
				this.location_show = false;
			},
			getType1(e){
				this.carMsg.box=this.type1;
				this.box=false;
			},
			getType2(e){
				this.carMsg.box=this.type2;
				this.box=false;
			},
			boxSelect(){
				this.box=true;
			},
			close() {
				this.box=false;
			},
			/*司机选择 */
			seleceDriver: function(e) {
				let driverId = e.detail.value;
				let type = this.selectDriver[driverId];
				this.driver = type.realname;
				this.driverId = e.detail.value;

			},
			/*车辆类型选择 */
			seleceYears: function(e) {
				let index = e.detail.value;
				let type = this.selectType[index];
				this.addcar_type = type.type_name;
				this.index = e.detail.value;
				this.type_id = type.type_id;
				//console.log(this.type_id)
			},
			/*获取司机*/
			getDriver() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._get('user.index/my_driver', {}, function(res) {
					self.selectDriver = res.data.driver;
					self.loadding = false;
					uni.hideLoading();
				});
			},
			getCar_type() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._get('home/getcartype', {}, function(res) {
					self.selectType = res.data.car_type;
					uni.hideLoading();
				});
			},
			gotoPage(path) {
				let self = this;
				if (path.startsWith('/')) {
					uni.navigateTo({
						url: path
					});
				} else {
					self[path]();
				}
			},
			chooseImages(type) {
				let self = this;

				// 上传图片idcard_pic1
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: (res) => {
						self.uploadFile(res.tempFilePaths[0], type);
					},
				});
			},
			delect(index) {
				uni.showModal({
					title: "提示",
					content: "是否要删除该图片",
					success: (res) => {
						if (res.confirm) {
							this.car_info3.splice(index, 1)
						}
					}
				})
			},
			uploadFile: function(filePath, type) {

				let self = this;
				let i = 0;
				let params = {
					token: uni.getStorageSync('token'),
					app_id: self.getAppId()
				};
				uni.showLoading({
					title: '图片上传中'
				});
				uni.uploadFile({
					url: self.websiteUrl + '/index.php?s=/api/file.upload/image',
					filePath: filePath,
					name: 'iFile',
					formData: params,
					success: function(res) {
						let result = typeof res.data === 'object' ? res.data : JSON.parse(res.data);
						if (result.code === 1) {
							let file_path = result.data.file_path;
							//self.imageList[type] = file_path;
							if (type == 'car_info3') {
								self.car_info3 = self.car_info3.concat(file_path);
							} else {
								self.imageList[type] = file_path;
							}
						}
					},
					complete: function() {
						i++;
						uni.hideLoading();
					}
				});
			},
			formSubmit() {
				let self = this;
				let formdata = {};
				
				if (self.addcar_type == '') {
					uni.showToast({
						title: '请选择车辆类型',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				let regExp = /^([京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][A-Za-z][1-9DF][1-9A-Za-z]\d{3}[1-9DF]|[京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][A-Ya-y][\dA-Za-z]{5})$/
				//let regExp = /(^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Za-z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$)/
				if (!regExp.test(self.addcar_plate)) {
					uni.showToast({
						title: '车牌号有误,请重填！',
						duration: 2000,
						icon: 'none'
					});
					return;
				}
				if (!/^1(3|4|5|6|7|8|9)\d{9}$/.test(self.addcar_mobile)) {
					uni.showToast({
						title: '手机有误,请重填！',
						duration: 2000,
						icon: 'none'
					});
					return;
				}
				// if (self.addcar_mobile == '') {
				// 	uni.showToast({
				// 		title: '请输入手机号',
				// 		duration: 2000,
				// 		icon: 'none'
				// 	});
				// 	return;
				// }
				if (self.imageList.car_info1 == '') {
					uni.showToast({
						title: '请上传车辆保险',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				if (self.imageList.car_info2 == '') {
					uni.showToast({
						title: '请上传车辆年检',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				if (self.imageList.car_info4 == '') {
					uni.showToast({
						title: '请上传车辆照片',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				if (self.carMsg.address == '') {
					uni.showToast({
						title: '请选择卖车地点',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				if (self.carMsg.introduce == '') {
					uni.showToast({
						title: '请输入车辆介绍',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				if (self.carMsg.type == '') {
					uni.showToast({
						title: '请输入正确的车辆品牌',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				if (self.carMsg.journey == '') {
					uni.showToast({
						title: '请输入正确的表显里程',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				self.nowDate();
				//let aa = /^\d{4}(\-)\d{1,2}\1\d{1,2}$/;
				//console.log(time)
				if(self.carMsg.time=='' ||self.carMsg.time>self.nowdate){
					uni.showToast({
						title: '请选择正确的上牌时间',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				// let aa = /^\d{4}-\d{1,2}-\d{1,2}/;
				// if(!aa.test(self.carMsg.time)){
				// 	uni.showToast({
				// 		title: '请输入正确的上牌时间',
				// 		duration: 1000,
				// 		icon: 'none'
				// 	});
				// 	return false;
				// }
				if (self.carMsg.time == '') {
					uni.showToast({
						title: '请输入正确的上牌时间',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				if (self.carMsg.discharge == '') {
					uni.showToast({
						title: '请输入出售价格',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				if (self.carMsg.journey == '') {
					uni.showToast({
						title: '请选择变速箱',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				let num =/^[+]{0,1}(\d+)$/;
				if (!num.test(self.carMsg.transfer)) {
					uni.showToast({
						title: '请输入正确的车辆过户次数',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				if (self.carMsg.price == '') {
					uni.showToast({
						title: '请输入正确的新车含税价',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				formdata.car_info1 = self.imageList.car_info1;
				formdata.car_info2 = self.imageList.car_info2;
				formdata.car_info3 = self.imageList.car_info4;
				formdata.addcar_plate = self.addcar_plate;
				formdata.mobile = self.addcar_mobile;
				formdata.addcar_type = self.type_id;
				formdata.product_address=self.carMsg.address;
				formdata.product_introduce=self.carMsg.introduce;
				
				formdata.product_type=self.carMsg.type;
				formdata.product_journey=self.carMsg.journey;
				formdata.product_time=self.carMsg.time;
				formdata.product_discharge=self.carMsg.discharge;
				formdata.product_box=self.carMsg.box;
				formdata.product_transfer=self.carMsg.transfer;
				formdata.product_price=self.carMsg.price;
				
				//formdata.type_id = self.index;
				formdata.distribution = 0;
				console.log(formdata);
				//return;
				
				uni.showLoading({
					title: '正在提交',
				});
				self._post(
					'user.add/add_usecar',
					formdata,
					result => {
						// 记录token user_id
						// uni.setStorageSync('token', result.data.token);
						// uni.setStorageSync('user_id', result.data.user_id);
						if (result.code == 1) {
							uni.showToast({
								title: '成功！',
								duration: 2000,
								icon: 'none'
							});
							//console.log("添加二手车")
							self.gotoPage('/pages/user/user-car/user-car');
						}
						// 执行回调函数
						// uni.navigateBack();
					},

					false,
					() => {
						uni.hideLoading();
					}
				)
			}
		}
	}
</script>

<style lang="scss">
	@import 'add-usercar.scss';
</style>
